package edu.ccut.saturn.component.impl.mock;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;

public class MockSession implements HttpSession {
	
	private Map<String, Object> map = new HashMap<String, Object>();
	
	private ServletContext mockServletContext = new MockServletContext();

	public MockSession() {
		
	}
	
	@SuppressWarnings("unchecked")
	public MockSession(HttpSession session) {
		Enumeration<String>	names = session.getAttributeNames();
		
		while (names.hasMoreElements()) {
			String key = names.nextElement();
			this.map.put(key, session.getAttribute(key));
		}
		
		this.mockServletContext = new MockServletContext(session.getServletContext());
	}
	
	public Object getAttribute(String arg0) {
		return map.get(arg0);
	}

	@SuppressWarnings("unchecked")
	public Enumeration getAttributeNames() {
		return new MockEnumeration(this.map);
	}

	public long getCreationTime() {
		return 0;
	}

	public String getId() {
		return null;
	}

	public long getLastAccessedTime() {
		return 0;
	}

	public int getMaxInactiveInterval() {
		return 0;
	}

	public ServletContext getServletContext() {
		return this.mockServletContext;
	}

	@SuppressWarnings("deprecation")
	public HttpSessionContext getSessionContext() {
		return null;
	}

	public Object getValue(String arg0) {
		return null;
	}

	public String[] getValueNames() {
		return null;
	}

	public void invalidate() {

	}

	public boolean isNew() {
		return false;
	}

	public void putValue(String arg0, Object arg1) {

	}

	public void removeAttribute(String arg0) {
		this.map.remove(arg0);
	}

	public void removeValue(String arg0) {

	}

	@SuppressWarnings("unchecked")
	public void setAttribute(String arg0, Object arg1) {
		this.map.put(arg0, arg1);
	}

	public void setMaxInactiveInterval(int arg0) {

	}
}
